from flask import Blueprint, request, url_for, session, redirect

admin_blu = Blueprint("admin", __name__, url_prefix="/admin")

from . import views


@admin_blu.before_request
def before_request():
    """
    判断是不是登录界面的请求
    :return:
    """
    if not request.url.endswith(url_for('admin.login')):
        user_id = session.get('user_id')
        is_admin = session.get("is_admin")

        if not user_id or not is_admin:
            return redirect('/')
